var input = document.getElementById("upload");
input.addEventListener('change',handleFile,false);
var fd = new FormData();
function handleFile(){
    var preview = document.getElementById('preview');
    var uploadButton = document.getElementById('uploadButton');
    if(typeof FileReader == undefined&&new FileReader().readAsDataURL){
        alert("您浏览器不支持上传图片！")
    }else {
        var files = input.files;
        for(var k=0;k<files.length;k++){
            if(!/image\/\w+/.test(files[k].type)){
                alert("请选择正确的文件！")
            }else{
                var reader = new FileReader();
                reader.readAsDataURL(files[k]);
                reader.onload = function(){
                    var img = document.createElement('img');
                    $(preview).html(img);
                    // preview.insertBefore(img,uploadButton);
                    img.src = this.result;
                    fd.append("src", this.result);
                };
                $("#uploadButton").hide();
            }
        }
    }
}

$("#registerPlayerUp").click(function () {
    if ($("#name").val() === "" || $("#name").val() === null || $("#name").val() === undefined) {alert('请填写姓名');return false;}
    if ($("#sex").val() === "" || $("#sex").val() === null || $("#sex").val() === undefined) {alert('请填写性别');return false;}
    if ($("#age").val() === "" || $("#age").val() === null || $("#age").val() === undefined) {alert('请填写年龄');return false;}
    if ($("#company").val() === "" || $("#company").val() === null || $("#company").val() === undefined) {alert('请填写单位');return false;}
    if ($("#phone").val() === "" || $("#phone").val() === null || $("#phone").val() === undefined) {alert('请填写电话');return false;}
    fd.append("name", $("#name").val());
    fd.append("sex", $("#sex").val());
    fd.append("age", $("#age").val());
    fd.append("company", $("#company").val());
    fd.append("phone", $("#phone").val());
    fd.append("email", $("#email").val());
    fd.append("id", $("#id").val());
    $.ajax({
        url: Feng.ctxPath + "/caseSelectionVote/registerPlayerUp",
        type: "post",
        traditional: true,
        data: fd,
        processData: false,
        contentType: false,
        success: function (data) {
            Feng.success('操作成功!');
            window.location.href = Feng.ctxPath + "/caseSelectionVote/personalCenter";
        },
        error: function (data) {
            this.fd = new FormData();
            alert('内部故障!');
        }
    });
});

$("#toback").click(function () {
    window.location.href = Feng.ctxPath + "/caseSelectionVote/personalCenter";
});